﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_AddProduct : System.Web.UI.Page
{
    CategoryDAL categoryDAL = new CategoryDAL();
    int CategoryID = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["adminlogin"] == null)
        {
            Response.Redirect("adminlogin.aspx");
        }
        DropDownListCategory.DataSource = categoryDAL.GetAllCategory();
        DropDownListCategory.DataBind();
    }
    protected void btnAddProduct_Click(object sender, EventArgs e)
    {
        ProductBus productBus = new ProductBus();
        Product objProduct = new Product();
        //lay id cua category
        DataTable dt = new DataTable();
        dt = categoryDAL.GetCategoryID(DropDownListCategory.SelectedItem.ToString());
        CategoryID = Convert.ToInt32(dt.Rows[0]["cat_id"].ToString());
        //set cho doi tuong
        objProduct.CatID = CategoryID;
        objProduct.PdName = txtProductName.Text;
        objProduct.PdDescription = txtDescription.Text;
        objProduct.PdQuantity = Convert.ToInt32(txtQuantity.Text);
        objProduct.PdPrice = Convert.ToDecimal(txtPrice.Text);
        objProduct.PdImage = "../images/"+FileUploadImageProduct.FileName;
        FileUploadImageProduct.SaveAs(Server.MapPath("~/images/"+FileUploadImageProduct.FileName));
        productBus.InsertProduct(objProduct);
    }
}
